package main

import (
	"os"

	"gitee.com/fanshuaiself/wss-gateway/cmd"
	"gitee.com/fanshuaiself/wss-gateway/constants"
	"gitee.com/fanshuaiself/wss-gateway/pkg/nacos"
	"gitee.com/fanshuaiself/wss-gateway/pkg/prom"
	"gitee.com/fanshuaiself/wss-gateway/pkg/redis"
	log "github.com/sirupsen/logrus"
)

func main() {
	config := loadConfig()
	nacos.InitNacos(config)
	redis.Init(config)
	prom.Init()

	kernelHub := cmd.NewKernelHub()
	if err := kernelHub.Start(); err != nil {
		log.Fatal(err)
	}

}

func loadConfig() *constants.Config {
	nacosServer, ok := os.LookupEnv("SPRING_CLOUD_NACOS_DISCOVERY_SERVER_ADDR")
	if !ok {
		log.Fatal("环境变量中没有找到nacos注册中心地址")
	}

	nacosServiceName, ok := os.LookupEnv("MESH_APP")
	if !ok {
		nacosServiceName = "crm-kehan-wss"
	}

	nacosServiceGroup, _ := os.LookupEnv("SPRING_CLOUD_NACOS_DISCOVERY_METADATA_GROUP")
	return &constants.Config{
		NacosServer: nacosServer,
		NacosServiceName: nacosServiceName,
		NacosServiceGroup: nacosServiceGroup,
	}
}